<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserCouponTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable('user_coupon')) {
            Schema::create('user_coupon', function (Blueprint $table) {
                $table->increments('user_coupon_id')->comment('主键ID');
                $table->unsignedInteger('coupon_id')->index('coupon_id')->comment('优惠券ID');
                $table->string('coupon_name')->default('')->comment('优惠券名称');
                $table->unsignedTinyInteger('coupon_type')->default(10)->comment('优惠券类型(10满减券 20折扣券)');
                $table->decimal('reduce_price', 10)->unsigned()->default(0.00)->comment('满减券-减免金额');
                $table->unsignedTinyInteger('discount')->default(0)->comment('折扣券-折扣率(0-100)');
                $table->decimal('min_price', 10)->unsigned()->default(0.00)->comment('最低消费金额');
                $table->unsignedTinyInteger('expire_type')->default(10)->comment('到期类型(10领取后生效 20固定时间)');
                $table->unsignedInteger('expire_day')->default(0)->comment('领取后生效-有效天数');
                $table->unsignedInteger('start_time')->default(0)->comment('有效期开始时间');
                $table->unsignedInteger('end_time')->default(0)->comment('有效期结束时间');
                $table->unsignedTinyInteger('apply_range')->default(10)->comment('适用范围(10全部商品 20指定商品)');
                $table->text('apply_range_config')->nullable()->comment('适用范围配置(json格式)');
                $table->unsignedTinyInteger('is_expire')->default(0)->comment('是否过期(0未过期 1已过期)');
                $table->unsignedTinyInteger('is_use')->default(0)->comment('是否已使用(0未使用 1已使用)');
                $table->unsignedInteger('user_id')->default(0)->index('user_id')->comment('用户ID');
                $table->unsignedInteger('store_id')->default(0)->index('store_id')->comment('商城ID');
                $table->string('get_way', 100)->default('')->comment('获取方式');
                $table->string('coupon_code', 20)->default('')->comment('优惠码');
                $table->timestamps();
                $table->softDeletes();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_coupon');
    }
}
